import request from '@/utils/request'
import type { ApiResponse } from '@/types/common'
import type { Seal, Asset, MeetingRoom, Vehicle, Approval, FlowModule } from '../types/adm'

// 行政管理相关API接口定义
export const admApi = {
  // 印章管理相关接口
  // 获取印章列表
  getSealList: (params: any): Promise<ApiResponse<Seal[]>> => {
    return request({
      url: '/api/adm/seal/list',
      method: 'get',
      params,
    })
  },

  // 添加印章
  addSeal: (data: any): Promise<ApiResponse<Seal>> => {
    return request({
      url: '/api/adm/seal/add',
      method: 'post',
      data,
    })
  },

  // 编辑印章
  editSeal: (data: any): Promise<ApiResponse<Seal>> => {
    return request({
      url: '/api/adm/seal/edit',
      method: 'post',
      data,
    })
  },

  // 删除印章
  deleteSeal: (id: number): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/adm/seal/delete',
      method: 'post',
      data: { id },
    })
  },

  // 资产管理相关接口
  // 获取资产列表
  getAssetList: (params: any): Promise<ApiResponse<Asset[]>> => {
    return request({
      url: '/api/adm/asset/list',
      method: 'get',
      params,
    })
  },

  // 添加资产
  addAsset: (data: any) => {
    return request({
      url: '/api/adm/asset/add',
      method: 'post',
      data,
    })
  },

  // 编辑资产
  editAsset: (data: any) => {
    return request({
      url: '/api/adm/asset/edit',
      method: 'post',
      data,
    })
  },

  // 删除资产
  deleteAsset: (id: number) => {
    return request({
      url: '/api/adm/asset/delete',
      method: 'post',
      data: { id },
    })
  },

  // 会议室管理相关接口
  // 获取会议室列表
  getMeetingRoomList: (params: any): Promise<ApiResponse<MeetingRoom[]>> => {
    return request({
      url: '/api/adm/meeting_room/list',
      method: 'get',
      params,
    })
  },

  // 添加会议室
  addMeetingRoom: (data: any) => {
    return request({
      url: '/api/adm/meeting_room/add',
      method: 'post',
      data,
    })
  },

  // 编辑会议室
  editMeetingRoom: (data: any) => {
    return request({
      url: '/api/adm/meeting_room/edit',
      method: 'post',
      data,
    })
  },

  // 删除会议室
  deleteMeetingRoom: (id: number) => {
    return request({
      url: '/api/adm/meeting_room/delete',
      method: 'post',
      data: { id },
    })
  },

  // 车辆管理相关接口
  // 获取车辆列表
  getVehicleList: (params: any): Promise<ApiResponse<Vehicle[]>> => {
    return request({
      url: '/api/adm/vehicle/list',
      method: 'get',
      params,
    })
  },

  // 添加车辆
  addVehicle: (data: any) => {
    return request({
      url: '/api/adm/vehicle/add',
      method: 'post',
      data,
    })
  },

  // 编辑车辆
  editVehicle: (data: any) => {
    return request({
      url: '/api/adm/vehicle/edit',
      method: 'post',
      data,
    })
  },

  // 删除车辆
  deleteVehicle: (id: number) => {
    return request({
      url: '/api/adm/vehicle/delete',
      method: 'post',
      data: { id },
    })
  },

  // 审批管理相关接口
  // 获取审批列表
  getApprovalList: (params: any): Promise<ApiResponse<Approval[]>> => {
    return request({
      url: '/api/adm/flow/list',
      method: 'get',
      params,
    })
  },

  // 添加审批
  addApproval: (data: any) => {
    return request({
      url: '/api/adm/flow/add',
      method: 'post',
      data,
    })
  },

  // 编辑审批
  editApproval: (data: any) => {
    return request({
      url: '/api/adm/flow/edit',
      method: 'put',
      data,
    })
  },

  // 删除审批
  deleteApproval: (id: number) => {
    return request({
      url: '/api/adm/flow/del',
      method: 'delete',
      data: { id },
    })
  },

  // 审批操作
  approveApproval: (data: { id: number; status: string; remark?: string }) => {
    return request({
      url: '/api/adm/flow/set_status',
      method: 'post',
      data,
    })
  },

  // 审批模块管理相关接口
  // 获取审批模块列表
  getFlowModuleList: (params: any): Promise<ApiResponse<FlowModule[]>> => {
    return request({
      url: '/api/adm/flow_module/list',
      method: 'get',
      params,
    })
  },

  // 查看审批模块详情
  viewFlowModule: (id: number): Promise<ApiResponse<FlowModule>> => {
    return request({
      url: '/api/adm/flow_module/view',
      method: 'get',
      params: { id },
    })
  },

  // 获取启用的审批模块列表
  getActiveFlowModuleList: (): Promise<ApiResponse<FlowModule[]>> => {
    return request({
      url: '/api/adm/flow_module/active_list',
      method: 'get',
    })
  },

  // 添加审批模块
  addFlowModule: (data: any): Promise<ApiResponse<FlowModule>> => {
    return request({
      url: '/api/adm/flow_module/add',
      method: 'post',
      data,
    })
  },

  // 编辑审批模块
  editFlowModule: (data: any): Promise<ApiResponse<FlowModule>> => {
    return request({
      url: '/api/adm/flow_module/edit',
      method: 'post',
      data,
    })
  },

  // 删除审批模块
  deleteFlowModule: (id: number): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/adm/flow_module/delete',
      method: 'post',
      data: { id },
    })
  },

  // 设置审批模块状态
  setFlowModuleStatus: (data: { id: number; status: number }): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/adm/flow_module/set_status',
      method: 'post',
      data,
    })
  },
}

// 向后兼容导出
export const {
  getSealList,
  addSeal,
  editSeal,
  deleteSeal,
  getAssetList,
  addAsset,
  editAsset,
  deleteAsset,
  getMeetingRoomList,
  addMeetingRoom,
  editMeetingRoom,
  deleteMeetingRoom,
  getVehicleList,
  addVehicle,
  editVehicle,
  deleteVehicle,
  getApprovalList,
  addApproval,
  editApproval,
  deleteApproval,
  approveApproval,
  // 审批模块相关接口
  getFlowModuleList,
  viewFlowModule,
  getActiveFlowModuleList,
  addFlowModule,
  editFlowModule,
  deleteFlowModule,
  setFlowModuleStatus,
} = admApi
